package com.psa.agent;

import android.util.TypedValue;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import com.psa.system.PersonDocumentActivity;
import com.psa.system.R;
import com.wxw.BaseLibrary.adapter.ViewsHelper;
import com.wxw.BaseLibrary.element.IObjectListAdapterAgent;
import com.wxw.BaseLibrary.tool.ScreenUtils;

/**
 *
 * @author david
 * @date 2017-11-23
 */
public class PersonDocumentItemAgent implements IObjectListAdapterAgent {

    @Override
    public int getResourceID() {
        return R.layout.object_list_item;
    }

    @Override
    public void fillContent(View view, Object o) {
        if (view != null && o instanceof PersonDocumentActivity.PersonDocument) {
            ViewsHelper helper = null;
            if (view.getTag() == null) {
                helper = new ViewsHelper();
                helper.getViewMap().put("text", view.findViewById(R.id.textView));
                ImageView imageView = (ImageView)view.findViewById(R.id.iv_icon);
                helper.getViewMap().put("icon", imageView);
                ViewGroup.LayoutParams lp = imageView.getLayoutParams();
                lp.height = ScreenUtils.convertScale(view.getContext(), 100);
                lp.width = lp.height;
                imageView.setLayoutParams(lp);
                ((TextView)helper.getViewMap().get("text")).setTextSize(TypedValue.COMPLEX_UNIT_SP, 20);
                view.setTag(helper);
            } else {
                helper = (ViewsHelper)view.getTag();
            }
            helper.setText("text", o.toString());
            helper.setImageResource("icon", ((PersonDocumentActivity.PersonDocument)o).getIcon());
        }
    }
}
